<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.4"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Flow: boost::filesystem Namespace Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">Flow<span id="projectnumber">&#160;2.0.0</span>
   </div>
   <div id="projectbrief">Flow project: Public API.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>boost</b></li><li class="navelem"><a class="el" href="namespaceboost_1_1filesystem.html">filesystem</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle"><div class="title">boost::filesystem Namespace Reference</div></div>
</div><!--header-->
<div class="contents">

<p>We may add some ADL-based overloads into this namespace outside <code>flow</code>.  
<a href="namespaceboost_1_1filesystem.html#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a5fa05fd030711d6d8c76139467b13256"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespaceboost_1_1filesystem.html#a5fa05fd030711d6d8c76139467b13256">validate</a> (boost::any &amp;target, const std::vector&lt; std::string &gt; &amp;user_values, path *, int)</td></tr>
<tr class="memdesc:a5fa05fd030711d6d8c76139467b13256"><td class="mdescLeft">&#160;</td><td class="mdescRight">ADL-based overload of boost.program_options <code><a class="el" href="namespaceboost_1_1filesystem.html#a5fa05fd030711d6d8c76139467b13256" title="ADL-based overload of boost.program_options validate() to allow for empty boost::filesystem::path val...">validate()</a></code> to allow for empty <code>boost::filesystem::path</code> values in <a class="el" href="namespaceflow_1_1cfg.html" title="Flow module that facilitates configuring modules, such as applications and APIs, via statically and/o...">flow::cfg</a> config parsing as well as any other boost.program_options parsing in the application.  <a href="namespaceboost_1_1filesystem.html#a5fa05fd030711d6d8c76139467b13256">More...</a><br /></td></tr>
<tr class="separator:a5fa05fd030711d6d8c76139467b13256"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >We may add some ADL-based overloads into this namespace outside <code>flow</code>. </p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a5fa05fd030711d6d8c76139467b13256" name="a5fa05fd030711d6d8c76139467b13256"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a5fa05fd030711d6d8c76139467b13256">&#9670;&nbsp;</a></span>validate()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void boost::filesystem::validate </td>
          <td>(</td>
          <td class="paramtype">boost::any &amp;&#160;</td>
          <td class="paramname"><em>target</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const std::vector&lt; std::string &gt; &amp;&#160;</td>
          <td class="paramname"><em>user_values</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">path *&#160;</td>
          <td class="paramname">, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname">&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>ADL-based overload of boost.program_options <code><a class="el" href="namespaceboost_1_1filesystem.html#a5fa05fd030711d6d8c76139467b13256" title="ADL-based overload of boost.program_options validate() to allow for empty boost::filesystem::path val...">validate()</a></code> to allow for empty <code>boost::filesystem::path</code> values in <a class="el" href="namespaceflow_1_1cfg.html" title="Flow module that facilitates configuring modules, such as applications and APIs, via statically and/o...">flow::cfg</a> config parsing as well as any other boost.program_options parsing in the application. </p>
<p >Likely there's no need to call this directly: it is invoked by boost.program_options when parsing <code>path</code>s.</p>
<p >More precisely: This has ~two effects:</p><ul>
<li><a class="el" href="classflow_1_1cfg_1_1Option__set.html" title="The core config-parsing facility, which builds parsing/comparison/output capabilities on top of a giv...">flow::cfg::Option_set</a> (and <a class="el" href="classflow_1_1cfg_1_1Config__manager.html" title="Manages a config setup, intended for a single daemon process, by maintaining 1 or more set(s) of stat...">flow::cfg::Config_manager</a> and anything else built on <code>Option_set</code>) will successfully parse an empty (or all-spaces) value for a setting of type <code>boost::filesystem::path</code>, resulting in a <code>path</code> equal to a default-constructed <code>path()</code>.<ul>
<li>You may still disallow it via a validator expression in <a class="el" href="option__set_8hpp.html#ae6bc0bcf28a53682a4c9a5fbe3a3837f" title="Macro the user must use, as prescribed in the flow::cfg::Option_set constructor doc header discussing...">FLOW_CFG_OPTION_SET_DECLARE_OPTION()</a> as usual. (Sometimes an empty "path" value is useful as a special or sentinel value.) Such <a class="el" href="namespaceflow_1_1cfg.html" title="Flow module that facilitates configuring modules, such as applications and APIs, via statically and/o...">flow::cfg</a>-user-specified individual-option-validator checking, internally, occurs after (and only if) the lower-level parsing already succeeded.</li>
</ul>
</li>
<li>Any other use (even outside of <a class="el" href="namespaceflow_1_1cfg.html" title="Flow module that facilitates configuring modules, such as applications and APIs, via statically and/o...">flow::cfg</a>) of boost.program_options to parse a <code>path</code> will now also allow an empty value (on command line, in file, etc.) in the same application.</li>
</ul>
<h3>Rationale</h3>
<p >Allowing empty <code>path</code>s in <a class="el" href="namespaceflow_1_1cfg.html" title="Flow module that facilitates configuring modules, such as applications and APIs, via statically and/o...">flow::cfg</a> is required for usability. It was a common use case to allow for a blank special value for path settings. However trying to in fact provide an empty value in a <a class="el" href="namespaceflow_1_1cfg.html" title="Flow module that facilitates configuring modules, such as applications and APIs, via statically and/o...">flow::cfg</a> file (e.g., simply <code>log-file=</code>) resulted in an "Invalid argument" error message and refusal of <a class="el" href="classflow_1_1cfg_1_1Option__set.html#a4ca1b50ec692a98865e4afde76d04128" title="Enters into (from CANONICAL state) or continues in PARSING state by parsing the config source in the ...">flow::cfg::Option_set::parse_config_file()</a> to successfully parse.</p>
<p >(The following discussion is about implementation details and would normally be omitted from this public-facing API doc header. However, in this slightly unusual (for Flow) situation the solution happens to subtly affect code outside of <a class="el" href="namespaceflow_1_1cfg.html" title="Flow module that facilitates configuring modules, such as applications and APIs, via statically and/o...">flow::cfg</a>. Therefore it is appropriate to discuss these internals here.)</p>
<p >The reason for this problem: <a class="el" href="namespaceflow_1_1cfg.html" title="Flow module that facilitates configuring modules, such as applications and APIs, via statically and/o...">flow::cfg</a> uses boost.program_options for config source (especially file) parsing. By default, when parsing a string into the proper type <code>T</code> (here <code>T</code> being <code>path</code>), boost.program_options uses <code>istream &gt;&gt; T</code> overload. Turns out that reading a blank from a stream into <code>path</code> causes the <code>istream</code> bad-bit to set, meaning <code>lexical_cast</code> throws <code>bad_lexical_cast</code>; boost.program_options then manifests this as an arg parse error. (If <code>T</code> were <code>std::string</code>, by contrast, no such problem would occur: <code>istream &gt;&gt; string</code> will happily accept a blank string.)</p>
<p >boost.program_options clearly suggests the proper way to custom-parse types at <a href="https://www.boost.org/doc/libs/1_78_0/doc/html/program_options/howto.html#id-1.3.32.6.7">https://www.boost.org/doc/libs/1_78_0/doc/html/program_options/howto.html#id-1.3.32.6.7</a> &ndash; namely, define a <code><a class="el" href="namespaceboost_1_1filesystem.html#a5fa05fd030711d6d8c76139467b13256" title="ADL-based overload of boost.program_options validate() to allow for empty boost::filesystem::path val...">validate()</a></code> overload in the same namespace as type <code>T</code>, with a <code>T</code>-typed arg. ADL (argument-dependent lookup) will then use that overload &ndash; instead of the default one, which simply invokes <code>lexical_cast</code> (i.e., <code>istream&gt;&gt;</code>) &ndash; and reports an error if that throws. This is the same technique used to conveniently select <code><a class="el" href="namespaceflow_1_1net__flow.html#ab38246018ee64662d208371c55ffb1bd" title="Free function that returns remote_endpoint.hash(); has to be a free function named hash_value for boo...">hash_value()</a></code> for <code>unordered_*</code>; <code><a class="el" href="namespaceflow_1_1log.html#a1b475cd2cc2e476aa96c002927bf1690" title="Log_context ADL-friendly swap: Equivalent to val1.swap(val2).">swap()</a></code> for STL containers; etc.</p>
<p >This solves the problem. However, somewhat unusually, this imposes the same more-permissive semantics on <em>all</em> other uses of boost.program_options in any application linking Flow (which includes this overload). This is arguably not-great; ideally we'd affect <a class="el" href="namespaceflow_1_1cfg.html" title="Flow module that facilitates configuring modules, such as applications and APIs, via statically and/o...">flow::cfg</a> and nothing else. That said (1) there's no apparent alternative in boost.program_options; and more to the point (2) this feels like either an improvement or neutral. If an empty path must be disallowed, this can be done via <code>notifier()</code> (or just a manual check). So, all in all, this seemed fine.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">target</td><td><code>target</code> shall be loaded with the <code>path</code> on success. Otherwise we shall throw, per required boost.program_options semantics. </td></tr>
    <tr><td class="paramname">user_values</td><td>The (trimmed) raw strings from the user for this occurrence of the setting. In our case there must be only one, since a <code>path</code> has only one value. </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Mar 28 2025 22:55:32 for Flow by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4
</small></address>
</body>
</html>
